

#ifndef __DEV_LAMP_H__
#define dev_lamp

#include "iot_message.pb.h"
#include <stdint.h>

typedef union{
    struct{
        uint16_t res:1;
        uint16_t under_voltage : 1;     // 欠压   UV (Under Voltage) 欠压
        uint16_t over_voltage : 1;	    // 过压
        uint16_t over_load : 1;		    // 过载---OP (Over Power)--1:功率过高
        uint16_t open_load : 1;		    // 1:输出开路

        uint16_t short_circuit : 1;		// SC  (Short Circuit)  1:输出短路
        uint16_t start_fail : 1;		// US  (Un Start) 1:无法启动
        uint16_t under_temperature : 1; // 温度过低
        uint16_t over_temperature : 1;	// 温度过高
        uint16_t leak_current : 1;		// 漏电流保护
        
        uint16_t flooding :1 ;          // 水浸
        uint16_t res1:5;
    }bit;
    uint16_t data;
}waring_u;


typedef struct{
    waring_u warning_config;
    uint16_t under_voltage_threshold;//0.1v
    uint16_t over_voltage_threshold;//0.1v
    uint16_t over_load_threshold;//1w
    uint16_t leak_current_threshold;//1ma
    int8_t   over_temperature_threshold;
    int8_t   under_temperature_threshold;
}elec_threshold_t;

typedef struct{
    char soft_ver[33];
    char hard_ver[33];
    char production_info[33];
} lamp_info_t;


typedef enum{
    eUU,      //电压 V
//   eUfast, //快速电压
    eII_1,    //电流1 A
    eII_2,    //电流2 A
//    eIfast, //快速电流
    eleak,    //漏电流 A  ---统一单位A，使用时根据需求转换
    
    ePP_1,    //有功1 W
    ePP_2,    //有功2 W
//    eQQ,    //无功
//    eSS,    //视在
    ePF_1,    //功率因数1, 0~1
    ePF_2,    //功率因数2, 0~1
    
    eFQ,      //频率
    eEN_1,    //有功电能1 kwh
    eEN_2,    //

    evalue_max,
}elec_value_e;




//此处电参数（电压电流电能等）均为标准单位（漏电为mA）
typedef struct{
    float   f_elec[evalue_max];
    // int16_t temperature[2];
    // int8_t  flooding_sign;
    // int8_t  leak_ext_sign;
    uint32_t unsaved_Ep1;
    uint32_t unsaved_Ep2;
    uint64_t u64_Ep1;
    uint64_t u64_Ep2;
}elec_data_t;



typedef struct{
    uint8_t     is_open[2];
    waring_u    warning;
    uint8_t     brightness[2];
    int8_t      temperature;
    elec_data_t elec;
    elec_threshold_t threshold;
    lamp_info_t  info;
   //  char   dev_name_str[32];      
}lamp_attr_t;

extern lamp_attr_t lamp_attr;

/**
 * @brief 
 * 
 * @param out 
 */
void lamp_attr_get(lamp_attr_t* out);

/**
 * @brief 
 * 
 */
void lamp_param_init(void);




/**
 * @brief 
 * 
 * @param attr_id 
 * @param attr_out 
 */
void lamp_get_attr(uint16_t attr_id, IotModel* attr_out);


/**
 * @brief 
 * 
 * @param attr_in 
 * @return uint8_t 
 */
uint8_t lamp_set_attr(IotModel* attr_in);

#endif // ////---__DEV_LAMP_H__
